package com.vercon.common.room

import android.content.Context
import androidx.room.*
import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase
import com.vercon.common.room.dao.AppDataRoomDao
import com.vercon.common.room.entry.AppDataRoomInfo


@Database(entities = [AppDataRoomInfo::class],
    exportSchema = true,
    version = 1)
abstract class AppDataBase : RoomDatabase() {

    abstract fun AppDataRoomDao() : AppDataRoomDao //app信息



    companion object {

        @Volatile private var instance: AppDataBase? = null

        fun getInstance(context: Context): AppDataBase {
            return instance ?: synchronized(this) {
                instance ?: buildDatabase(context).also { instance = it }
            }
        }

        private fun buildDatabase(context: Context): AppDataBase {
            return Room.databaseBuilder(context, AppDataBase::class.java, "vercon_b53_appdata_db")
                .fallbackToDestructiveMigration().build()
        }
    }
}